<?php
namespace App\Services\Circle;


use App\Models\Circle;
use App\Models\User;

class GetLotteryUserService {

    public static function handle($circle_id, $lottery) {
        if (!$lottery)
            return $lottery;

        $key = Circle::CACHE_CIRCLE_LOTTERY_USER . '_' . $circle_id;
        return \Cache::remember($key, 3600, function () use($circle_id, $lottery) {
            foreach ($lottery as $key => &$item) {
                if ($key == 'desc')
                    continue;
                if ($item) {
                    $arr = explode(",", $item);
                    $res = User::whereIn('id', $arr)->select('id', 'nickname', 'avatar_url')->get()->toArray();
                    $lottery[$key] = $res;
                } else {
                    $lottery[$key] = [];
                }
            }
            return $lottery;
        });
    }
}